<?php

namespace Xp\Feedback;

class ConfigLoader
{
    protected array $config = [];

    public function __construct(?array $config)
    {
        if (empty($config)) {
            $file = __DIR__ . '/../config/feedback.php';
            if (file_exists($file)) {
                $this->config = require $file;
            } else {
                throw new \Exception("Configuration file not found: {$file}");
            }
        }else{
            $this->config = $config;
        }
    }

    public function get(string $key, $default = null)
    {
        return $this->config[$key] ?? $default;
    }
}